package com.wanbatv.wanba.ahitv.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DownloadManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.wanbatv.wanba.ahitv.R;
import com.wanbatv.wanba.ahitv.api.ApiBuilder;
import com.wanbatv.wanba.ahitv.api.ConfigUtils;
import com.wanbatv.wanba.ahitv.broadcast.DownloadTaskReceiver;
import com.wanbatv.wanba.ahitv.entity.DownloadTask;
import com.wanbatv.wanba.ahitv.util.AppUtil;
import com.wanbatv.wanba.ahitv.util.Behavior;
import com.wanbatv.wanba.ahitv.util.Crypto;
import com.wanbatv.wanba.ahitv.util.DataReport;
import com.wanbatv.wanba.ahitv.util.ProductInfo;
import com.wanbatv.wanba.ahitv.util.TVViewPager;
import com.wanbatv.wanba.ahitv.util.Util;
import com.wanbatv.wanba.ahitv.view.LoginDemo;
import com.wanbatv.wanba.ahitv.view.LoginZhongxinDemo;
import com.wanbatv.wanba.ahitv.view.Loginpage3;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import de.hdodenhof.circleimageview.CircleImageView;


public class LoginActivity extends FullScreenActivity {
    // apk下载广播接收器
    DownloadTaskReceiver receiver;

    public static int LANMU_NUM=0;
    static String device_id = Build.SERIAL;
    private TVViewPager viewpager;
    ArrayList<View> viewContainter = new ArrayList<View>();
    private DownAdapter mAdapter = null;
    ArrayList<View> viewContainter_geren = new ArrayList<View>();
    private TVViewPager viewpager_geren;
    private DownAdapter_Geren mAdapter_geren = null;
    ArrayList<View> viewContainter_all = new ArrayList<View>();
    private TVViewPager viewpager_all;
    private DownAdapter_All mAdapter_all = null;
    private TextView fit_main_time;
    private static final int msgKey1 = 1;
    private TextView login_tv1;
    private TextView login_tv2;
    private TextView login_tv3;
    private TextView login_tv11;
    private TextView login_tv21;
    private TextView login_tv31;
    private TextView login_zhongxin_tv1;
    private TextView login_zhongxin_tv2;
    private TextView login_zhongxin_tv3;
    private TextView login_zhongxin_tv4;
    private TextView login_zhongxin_tv5;
    private Map<String,Bitmap> map=new HashMap<String,Bitmap>();
    private ImageView login_zhongxin_geren;
    private ImageView login_zhongxin_all;
    private ImageView login_zhongxin_geren_iv1;
    private ImageView login_zhongxin_all_iv1;
    private boolean IS_geren=true;
    private ImageView login_zhongxin_left;
    private ImageView login_zhongxin_right;
    private TextView login_zhongxin_yema;
    private long exitTime;
    boolean[] shuzu_geren=new boolean[50];
    boolean[] shuzu_all=new boolean[50];
    private JSONArray arr_geren=null;
    private JSONArray arr_all=null;
    private int num_geren=0;
    private int num_all=0;
    ImageView demo2_iv1;
    ImageView demo2_iv2;
    ImageView demo2_iv3;
    ImageView demo2_iv4;
    ImageView demo2_iv5;
    private int yema_num;
    public static boolean is_dinggou=false;
    private int mCurrentPosition = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        Behavior.onAppStart(LoginActivity.this);
        DataReport.AppRetreat(this,"1000");
        dinggou();
        updateAPK("http://121.201.14.248:8061/appversion/last?flavor=anhui&type=release&app="+this.getPackageName()+"&platform=android",
                AppUtil.converVersionNameToInt(AppUtil.getAppVersionName(this)));
        for (int i=0;i<shuzu_geren.length;i++){
            shuzu_geren[i]=false;
        }
        for (int i=0;i<shuzu_all.length;i++){
            shuzu_all[i]=false;
        }
        viewpager=(TVViewPager)findViewById(R.id.viewpager);

        login_tv1=(TextView)findViewById(R.id.login_tv1);
        login_tv2=(TextView)findViewById(R.id.login_tv2);
        login_tv3=(TextView)findViewById(R.id.login_tv3);
        login_tv11=(TextView)findViewById(R.id.login_tv11);
        login_tv21=(TextView)findViewById(R.id.login_tv21);
        login_tv31=(TextView)findViewById(R.id.login_tv31);

        fit_main_time=(TextView)findViewById(R.id.fit_main_time);
        new TimeThread().start();
        final View v1 = LayoutInflater.from(LoginActivity.this).inflate(R.layout.login_page1, null);
        View v2 = LayoutInflater.from(LoginActivity.this).inflate(R.layout.login_page2, null);
        ViewGroup v3 = (ViewGroup) LayoutInflater.from(LoginActivity.this).inflate(
                R.layout.login_page3_demo, null);


        viewContainter.add(v1);
        viewContainter.add(v2);
        viewContainter.add(v3);
        RequestQueue rq_zi = Volley.newRequestQueue(LoginActivity.this.getApplicationContext());
        JsonObjectRequest request_zi = new JsonObjectRequest("http://61.191.46.214:8087/checkin/getcurrtotal?region=23", null,
                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject jsonObject) {
                        try {
                            JSONObject obj=jsonObject.getJSONObject("data");
                            JSONArray arr=obj.getJSONArray("list");
                            LoginDemo d1=(LoginDemo)v1.findViewById(R.id.login_demo1);
                            LoginDemo d2=(LoginDemo)v1.findViewById(R.id.login_demo2);
                            LoginDemo d3=(LoginDemo)v1.findViewById(R.id.login_demo3);
                            LoginDemo d4=(LoginDemo)v1.findViewById(R.id.login_demo4);
                            LoginDemo d5=(LoginDemo)v1.findViewById(R.id.login_demo5);
                            TextView tv1=(TextView)d1.findViewById(R.id.login_demo_tv);
                            TextView tv2=(TextView)d2.findViewById(R.id.login_demo_tv);
                            TextView tv3=(TextView)d3.findViewById(R.id.login_demo_tv);
                            TextView tv4=(TextView)d4.findViewById(R.id.login_demo_tv);
                            TextView tv5=(TextView)d5.findViewById(R.id.login_demo_tv);
                            for (int i=0;i<arr.length();i++){
                                JSONObject demo1=arr.getJSONObject(i);
                                String category=demo1.getString("category");
                                int currtotal=demo1.getInt("currtotal");
                                if(category.equals("101")){
                                    tv3.setText("当前人数"+currtotal+"人");
                                }else if(category.equals("103")){
                                    tv1.setText("当前人数"+currtotal+"人");
                                }
                                else if(category.equals("102")){
                                    tv4.setText("当前人数"+currtotal+"人");
                                }
                                else if(category.equals("106")){
                                    tv5.setText("当前人数"+currtotal+"人");
                                } else if(category.equals("110")){
                                    tv2.setText("当前人数"+currtotal+"人");
                                }else{

                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }

        );
        rq_zi.add(request_zi);
        viewpager_all=(TVViewPager)v2.findViewById(R.id.login_zhongxin_all_viewpager);
        viewpager_geren=(TVViewPager)v2.findViewById(R.id.login_zhongxin_geren_viewpager);
        mAdapter=new DownAdapter();
        viewpager.setAdapter(mAdapter);
        viewpager.setOffscreenPageLimit(1);
        viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                if (mCurrentPosition == 0) {

                    DataReport.PageRetreat(LoginActivity.this,"2100","100010");
                } else if (mCurrentPosition == 1) {

                    DataReport.PageRetreat(LoginActivity.this,"2100","100011");
                } else if (mCurrentPosition == 2) {

                    DataReport.PageRetreat(LoginActivity.this,"2100","100012");
                }
                if (i == 0) {
                    login_tv11.setTextColor(Color.parseColor("#fff799"));
                    login_tv21.setTextColor(Color.parseColor("#ffc49c"));
                    login_tv31.setTextColor(Color.parseColor("#ffc49c"));
                    login_tv1.setBackgroundResource(R.drawable.login_top2);
                    login_tv2.setBackgroundResource(R.drawable.login_top3);
                    login_tv3.setBackgroundResource(R.drawable.login_top3);
                    yema_num=1;
                    Behavior.onPagePause(LoginActivity.this,100001,"全部运动");
                    DataReport.PageRetreat(LoginActivity.this,"1100","100010");
                }
                if (i == 1) {
                    login_tv21.setTextColor(Color.parseColor("#fff799"));
                    login_tv11.setTextColor(Color.parseColor("#ffc49c"));
                    login_tv31.setTextColor(Color.parseColor("#ffc49c"));
                    login_tv2.setBackgroundResource(R.drawable.login_top2);
                    login_tv1.setBackgroundResource(R.drawable.login_top3);
                    login_tv3.setBackgroundResource(R.drawable.login_top3);
                    if(login_tv21.isFocused()){

                    }else{
                        if(yema_num==1){
                            login_zhongxin_geren_iv1.requestFocus();
                        }else{
                            login_zhongxin_all_iv1.requestFocus();
                        }
                    }
                    Behavior.onPagePause(LoginActivity.this,100001,"个人中心");
                    DataReport.PageRetreat(LoginActivity.this,"1100","100011");
                }
                if (i == 2) {
                    login_tv31.setTextColor(Color.parseColor("#fff799"));
                    login_tv21.setTextColor(Color.parseColor("#ffc49c"));
                    login_tv11.setTextColor(Color.parseColor("#ffc49c"));
                    login_tv3.setBackgroundResource(R.drawable.login_top2);
                    login_tv2.setBackgroundResource(R.drawable.login_top3);
                    login_tv1.setBackgroundResource(R.drawable.login_top3);
                    yema_num=3;
                    Behavior.onPagePause(LoginActivity.this,100001,"微信相册");
                    DataReport.PageRetreat(LoginActivity.this,"1100","100012");
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
        login_tv11.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    v.setBackgroundResource(R.drawable.main_title_background_focused);
                    viewpager.setCurrentItem(0);

                } else {
                   v.setBackgroundResource(R.drawable.fittime_guangbiao_tm);

                }
            }
        });
        login_tv21.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    v.setBackgroundResource(R.drawable.main_title_background_focused);
                    viewpager.setCurrentItem(1);

                } else {
                    v.setBackgroundResource(R.drawable.fittime_guangbiao_tm);

                }
            }
        });
        login_tv31.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    v.setBackgroundResource(R.drawable.main_title_background_focused);
                    viewpager.setCurrentItem(2);

                }else{
                    v.setBackgroundResource(R.drawable.fittime_guangbiao_tm);

                }
            }
        });
        LoginDemo demo1=(LoginDemo)v1.findViewById(R.id.login_demo1);
        LoginDemo demo2=(LoginDemo)v1.findViewById(R.id.login_demo2);
        LoginDemo demo3=(LoginDemo)v1.findViewById(R.id.login_demo3);
        LoginDemo demo4=(LoginDemo)v1.findViewById(R.id.login_demo4);
        LoginDemo demo5=(LoginDemo)v1.findViewById(R.id.login_demo5);
        ImageView demo1_iv1=(ImageView)demo1.findViewById(R.id.login_demo_iv1);
        ImageView demo1_iv2=(ImageView)demo2.findViewById(R.id.login_demo_iv1);
        ImageView demo1_iv3=(ImageView)demo3.findViewById(R.id.login_demo_iv1);
        ImageView demo1_iv4=(ImageView)demo4.findViewById(R.id.login_demo_iv1);
        ImageView demo1_iv5=(ImageView)demo5.findViewById(R.id.login_demo_iv1);
        demo2_iv1=(ImageView)demo1.findViewById(R.id.login_demo_iv2);
        demo2_iv2=(ImageView)demo2.findViewById(R.id.login_demo_iv2);
        demo2_iv3=(ImageView)demo3.findViewById(R.id.login_demo_iv2);
        demo2_iv4=(ImageView)demo4.findViewById(R.id.login_demo_iv2);
        demo2_iv5=(ImageView)demo5.findViewById(R.id.login_demo_iv2);

        demo2_iv1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it=new Intent();
                it.setClass(LoginActivity.this,ZhengdyActivity.class);
                startActivity(it);
                Behavior.onEvent(LoginActivity.this, 3020103, "点击郑多燕");
            }
        });
        demo2_iv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it=new Intent();
                it.setClass(LoginActivity.this,FittimeActivity.class);
                startActivity(it);
                Behavior.onEvent(LoginActivity.this, 3020110, "点击fittime");
            }
        });
        demo2_iv3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it=new Intent();
                it.setClass(LoginActivity.this,MikeLingChannelActivity.class);
                startActivity(it);
                Behavior.onEvent(LoginActivity.this, 3020101, "点击麦克林");
            }
        });
        demo2_iv4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it=new Intent();
                it.setClass(LoginActivity.this,RuijianChannelActivity.class);
                startActivity(it);
                Behavior.onEvent(LoginActivity.this, 3020102, "点击睿建");
            }
        });
        demo2_iv5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it=new Intent();
                it.setClass(LoginActivity.this,JianshencaoChannelActivity.class);
                startActivity(it);
                Behavior.onEvent(LoginActivity.this, 3020106, "点击健身操");
            }
        });
        demo1_iv2.setImageResource(R.drawable.login_tupian2);
        demo1_iv3.setImageResource(R.drawable.login_tupian3);
        demo1_iv4.setImageResource(R.drawable.login_tupian4);
        demo1_iv5.setImageResource(R.drawable.login_tupian5);
        login_zhongxin_tv1=(TextView)v2.findViewById(R.id.login_zhongxin_tv1);
        login_zhongxin_tv2=(TextView)v2.findViewById(R.id.login_zhongxin_tv2);
        login_zhongxin_tv3=(TextView)v2.findViewById(R.id.login_zhongxin_tv3);
        login_zhongxin_tv4=(TextView)v2.findViewById(R.id.login_zhongxin_tv4);
        login_zhongxin_tv5=(TextView)v2.findViewById(R.id.login_zhongxin_tv5);
        login_zhongxin_geren=(ImageView)v2.findViewById(R.id.login_zhongxin_geren);
        login_zhongxin_all=(ImageView)v2.findViewById(R.id.login_zhongxin_all);
        login_zhongxin_geren_iv1=(ImageView)v2.findViewById(R.id.login_zhongxin_geren_iv1);
        login_zhongxin_all_iv1 = (ImageView) v2.findViewById(R.id.login_zhongxin_all_iv1);
        if (v3.getChildAt(0) instanceof Loginpage3) {
            Loginpage3 loginPage3 = (Loginpage3) v3.getChildAt(0);
            loginPage3.setTagView(Loginpage3.shuaxin_button);
            loginPage3.setNextScreenFocusViewId(login_zhongxin_all_iv1.getId());
            loginPage3.init();
        }
//        login_zhongxin_geren_iv1.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if(IS_geren){
//
//                }else {
//                login_zhongxin_geren.setImageResource(R.drawable.login_zhongxin_geren_1);
//                login_zhongxin_all.setImageResource(R.drawable.login_zhongxin_all_2);
//                    viewpager_geren.setVisibility(View.VISIBLE);
//                    viewpager_all.setVisibility(View.GONE);
//                    if(viewContainter_geren.size()==0) {
//                        login_zhongxin_yema.setText(viewpager_geren.getCurrentItem() + 1 + "/1" );
//                    }else{
//                        login_zhongxin_yema.setText(viewpager_geren.getCurrentItem() + 1 + "/" + viewContainter_geren.size());
//
//                    }
//                if(viewpager_geren.getCurrentItem()==0){
//                    login_zhongxin_left.setVisibility(View.GONE);
//                    login_zhongxin_right.setVisibility(View.VISIBLE);
//                    if(viewContainter_geren.size()<=1){
//                        login_zhongxin_right.setVisibility(View.GONE);
//                    }
//                }
//                    if(viewpager_geren.getCurrentItem()>0){
//                        login_zhongxin_left.setVisibility(View.VISIBLE);
//                        login_zhongxin_right.setVisibility(View.VISIBLE);
//                        if(viewpager_geren.getCurrentItem()==viewContainter_geren.size()-1){
//                            login_zhongxin_right.setVisibility(View.GONE);
//                        }
//                    }
//
//                }
//                IS_geren=true;
//            }
//        });
//        login_zhongxin_all_iv1.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//               if(IS_geren) {
//                   login_zhongxin_geren.setImageResource(R.drawable.login_zhongxin_geren_2);
//                   login_zhongxin_all.setImageResource(R.drawable.login_zhongxin_all_1);
//                   viewpager_geren.setVisibility(View.GONE);
//                   viewpager_all.setVisibility(View.VISIBLE);
//                   login_zhongxin_yema.setText(viewpager_all.getCurrentItem()+1+ "/" + viewContainter_all.size());
//                   if(viewpager_all.getCurrentItem()==0){
//                       login_zhongxin_left.setVisibility(View.GONE);
//                       login_zhongxin_right.setVisibility(View.VISIBLE);
//                       if(viewContainter_all.size()==1){
//                           login_zhongxin_right.setVisibility(View.GONE);
//                       }
//                   }
//                   if(viewpager_all.getCurrentItem()>0){
//                       login_zhongxin_left.setVisibility(View.VISIBLE);
//                       login_zhongxin_right.setVisibility(View.VISIBLE);
//                       if(viewpager_all.getCurrentItem()==viewContainter_all.size()-1){
//                           login_zhongxin_right.setVisibility(View.GONE);
//                       }
//                   }
//               }else{
//
//               }
//                IS_geren=false;
//            }
//        });
        login_zhongxin_geren_iv1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    if (IS_geren) {

                    } else {
                        login_zhongxin_geren.setImageResource(R.drawable.login_zhongxin_geren_1);
                        login_zhongxin_all.setImageResource(R.drawable.login_zhongxin_all_2);
                        viewpager_geren.setVisibility(View.VISIBLE);
                        viewpager_all.setVisibility(View.GONE);
                        if(viewContainter_geren.size()==0) {
                            login_zhongxin_yema.setText(viewpager_geren.getCurrentItem() + 1 + "/1" );
                        }else{
                            login_zhongxin_yema.setText(viewpager_geren.getCurrentItem() + 1 + "/" + viewContainter_geren.size());

                        }                        if (viewpager_geren.getCurrentItem() == 0) {
                            login_zhongxin_left.setVisibility(View.GONE);
                            login_zhongxin_right.setVisibility(View.VISIBLE);
                            if (viewContainter_geren.size()<= 1) {
                                login_zhongxin_right.setVisibility(View.GONE);
                            }
                        }
                        if (viewpager_geren.getCurrentItem() > 0) {
                            login_zhongxin_left.setVisibility(View.VISIBLE);
                            login_zhongxin_right.setVisibility(View.VISIBLE);
                            if (viewpager_geren.getCurrentItem() == viewContainter_geren.size() - 1) {
                                login_zhongxin_right.setVisibility(View.GONE);
                            }
                        }

                    }
                    IS_geren = true;
                }
            }
        });
        login_zhongxin_all_iv1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    if(IS_geren) {
                        login_zhongxin_geren.setImageResource(R.drawable.login_zhongxin_geren_2);
                        login_zhongxin_all.setImageResource(R.drawable.login_zhongxin_all_1);
                        viewpager_geren.setVisibility(View.GONE);
                        viewpager_all.setVisibility(View.VISIBLE);
                        if(viewContainter_all.size()==0) {
                            login_zhongxin_yema.setText(viewpager_all.getCurrentItem() + 1 + "/1" );
                        }else{
                            login_zhongxin_yema.setText(viewpager_all.getCurrentItem() + 1 + "/" + viewContainter_all.size());

                        }                        if(viewpager_all.getCurrentItem()==0){
                            login_zhongxin_left.setVisibility(View.GONE);
                            login_zhongxin_right.setVisibility(View.VISIBLE);
                            if(viewContainter_all.size()<=1){
                                login_zhongxin_right.setVisibility(View.GONE);
                            }
                        }
                        if(viewpager_all.getCurrentItem()>0){
                            login_zhongxin_left.setVisibility(View.VISIBLE);
                            login_zhongxin_right.setVisibility(View.VISIBLE);
                            if(viewpager_all.getCurrentItem()==viewContainter_all.size()-1){
                                login_zhongxin_right.setVisibility(View.GONE);
                            }
                        }
                    }else{

                    }
                    if(viewpager.getCurrentItem()==2){
                        viewpager.setCurrentItem(1);
                    }
                    IS_geren=false;
                }
            }
        });
        login_zhongxin_left=(ImageView)v2.findViewById(R.id.login_zhongxin_left);
        login_zhongxin_right=(ImageView)v2.findViewById(R.id.login_zhongxin_right);
        login_zhongxin_yema=(TextView)v2.findViewById(R.id.login_zhongxin_yema);
        login_zhongxin_left.setVisibility(View.GONE);
        RequestQueue rq = Volley.newRequestQueue(this.getApplicationContext());
        JsonObjectRequest request = new JsonObjectRequest("http://61.191.46.214:8087/checkin/shared/user?userid="+ Util.getDeviceId(LoginActivity.this)+"&region=23", null,
                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject jsonObject) {
                        try {
                            JSONObject obj=jsonObject.getJSONObject("data");
                            JSONArray arr=obj.getJSONArray("list");
                            arr_geren=arr;
                            int a=arr.length()/4;
                            if(arr.length()%4!=0){
                                a+=1;
                            }
                            if(a==1){
                                login_zhongxin_right.setVisibility(View.GONE);
                            }
                            for (int i=0;i<a;i++) {
                                try {
                                    if (i == 0) {
                                        View v1_geren = LayoutInflater.from(LoginActivity.this).inflate(R.layout.login_zhongxin_viewpager_demo, null);
                                        viewContainter_geren.add(v1_geren);
                                        LoginZhongxinDemo demo1 = (LoginZhongxinDemo) v1_geren.findViewById(R.id.login_zhongxin_demo1);
                                        LoginZhongxinDemo demo2 = (LoginZhongxinDemo) v1_geren.findViewById(R.id.login_zhongxin_demo2);
                                        LoginZhongxinDemo demo3 = (LoginZhongxinDemo) v1_geren.findViewById(R.id.login_zhongxin_demo3);
                                        LoginZhongxinDemo demo4 = (LoginZhongxinDemo) v1_geren.findViewById(R.id.login_zhongxin_demo4);
                                        if (num_geren < arr.length()) {
                                            ImageView login_zhongxin_demo_bg = (ImageView) demo1.findViewById(R.id.login_zhongxin_demo_bg);
                                            TextView login_zhongxin_demo_tv1 = (TextView) demo1.findViewById(R.id.login_zhongxin_demo_tv1);
                                            TextView login_zhongxin_demo_tv2 = (TextView) demo1.findViewById(R.id.login_zhongxin_demo_tv2);
                                            TextView login_zhongxin_demo_tv3 = (TextView) demo1.findViewById(R.id.login_zhongxin_demo_tv3);
                                            TextView login_zhongxin_demo_tv4 = (TextView) demo1.findViewById(R.id.login_zhongxin_demo_tv4);
                                            TextView login_zhongxin_demo_tv5 = (TextView) demo1.findViewById(R.id.login_zhongxin_demo_tv5);
                                            ImageView login_zhongxin_demo_iv1 = (ImageView) demo1.findViewById(R.id.login_zhongxin_demo_iv1);
                                            final CircleImageView login_zhongxin_demo_touxiang = (CircleImageView) demo1.findViewById(R.id.login_zhongxin_demo_touxiang);
                                            JSONObject obj1 = arr.getJSONObject(num_geren);
                                            beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                                            biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                                            login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                                            login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                                            login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                                            int time = obj1.getInt("duration");
                                            login_zhongxin_demo_tv4.setText(time / 60 + " min");
                                            int col = time * 355 / 3600;
                                            login_zhongxin_demo_tv5.setText(col + " col");
                                            RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                                            ImageRequest imageRequest = new ImageRequest(
                                                    obj1.getString("wxPortrait"),
                                                    new Response.Listener<Bitmap>() {
                                                        @Override
                                                        public void onResponse(Bitmap response) {
                                                            login_zhongxin_demo_touxiang.setImageBitmap(response);
                                                            map.put(num_geren + "num1", response);
                                                        }
                                                    }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                                @Override
                                                public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                                }
                                            });
                                            mQueue.add(imageRequest);
                                        } else {
                                            demo1.setVisibility(View.GONE);
                                        }
                                        if (num_geren + 1 < arr.length()) {
                                            ImageView login_zhongxin_demo_bg = (ImageView) demo2.findViewById(R.id.login_zhongxin_demo_bg);
                                            TextView login_zhongxin_demo_tv1 = (TextView) demo2.findViewById(R.id.login_zhongxin_demo_tv1);
                                            TextView login_zhongxin_demo_tv2 = (TextView) demo2.findViewById(R.id.login_zhongxin_demo_tv2);
                                            TextView login_zhongxin_demo_tv3 = (TextView) demo2.findViewById(R.id.login_zhongxin_demo_tv3);
                                            TextView login_zhongxin_demo_tv4 = (TextView) demo2.findViewById(R.id.login_zhongxin_demo_tv4);
                                            TextView login_zhongxin_demo_tv5 = (TextView) demo2.findViewById(R.id.login_zhongxin_demo_tv5);
                                            ImageView login_zhongxin_demo_iv1 = (ImageView) demo2.findViewById(R.id.login_zhongxin_demo_iv1);
                                            final CircleImageView login_zhongxin_demo_touxiang = (CircleImageView) demo2.findViewById(R.id.login_zhongxin_demo_touxiang);
                                            JSONObject obj1 = arr.getJSONObject(num_geren + 1);
                                            beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                                            biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                                            login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                                            login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                                            login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                                            int time = obj1.getInt("duration");
                                            login_zhongxin_demo_tv4.setText(time / 60 + " min");
                                            int col = time * 355 / 3600;
                                            login_zhongxin_demo_tv5.setText(col + " col");
                                            RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                                            ImageRequest imageRequest = new ImageRequest(
                                                    obj1.getString("wxPortrait"),
                                                    new Response.Listener<Bitmap>() {
                                                        @Override
                                                        public void onResponse(Bitmap response) {
                                                            login_zhongxin_demo_touxiang.setImageBitmap(response);
                                                            map.put(num_geren + "num2", response);
                                                        }
                                                    }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                                @Override
                                                public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                                }
                                            });
                                            mQueue.add(imageRequest);
                                        } else {
                                            demo2.setVisibility(View.GONE);
                                        }
                                        if (num_geren + 2 < arr.length()) {
                                            ImageView login_zhongxin_demo_bg = (ImageView) demo3.findViewById(R.id.login_zhongxin_demo_bg);
                                            TextView login_zhongxin_demo_tv1 = (TextView) demo3.findViewById(R.id.login_zhongxin_demo_tv1);
                                            TextView login_zhongxin_demo_tv2 = (TextView) demo3.findViewById(R.id.login_zhongxin_demo_tv2);
                                            TextView login_zhongxin_demo_tv3 = (TextView) demo3.findViewById(R.id.login_zhongxin_demo_tv3);
                                            TextView login_zhongxin_demo_tv4 = (TextView) demo3.findViewById(R.id.login_zhongxin_demo_tv4);
                                            TextView login_zhongxin_demo_tv5 = (TextView) demo3.findViewById(R.id.login_zhongxin_demo_tv5);
                                            ImageView login_zhongxin_demo_iv1 = (ImageView) demo3.findViewById(R.id.login_zhongxin_demo_iv1);
                                            final CircleImageView login_zhongxin_demo_touxiang = (CircleImageView) demo3.findViewById(R.id.login_zhongxin_demo_touxiang);
                                            JSONObject obj1 = arr.getJSONObject(num_geren + 2);
                                            beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                                            biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                                            login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                                            login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                                            login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                                            int time = obj1.getInt("duration");
                                            login_zhongxin_demo_tv4.setText(time / 60 + " min");
                                            int col = time * 355 / 3600;
                                            login_zhongxin_demo_tv5.setText(col + " col");
                                            RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                                            ImageRequest imageRequest = new ImageRequest(
                                                    obj1.getString("wxPortrait"),
                                                    new Response.Listener<Bitmap>() {
                                                        @Override
                                                        public void onResponse(Bitmap response) {
                                                            login_zhongxin_demo_touxiang.setImageBitmap(response);
                                                            map.put(num_geren + "num3", response);
                                                        }
                                                    }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                                @Override
                                                public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                                }
                                            });
                                            mQueue.add(imageRequest);
                                        } else {
                                            demo3.setVisibility(View.GONE);
                                        }
                                        if (num_geren + 3 < arr.length()) {
                                            ImageView login_zhongxin_demo_bg = (ImageView) demo4.findViewById(R.id.login_zhongxin_demo_bg);
                                            TextView login_zhongxin_demo_tv1 = (TextView) demo4.findViewById(R.id.login_zhongxin_demo_tv1);
                                            TextView login_zhongxin_demo_tv2 = (TextView) demo4.findViewById(R.id.login_zhongxin_demo_tv2);
                                            TextView login_zhongxin_demo_tv3 = (TextView) demo4.findViewById(R.id.login_zhongxin_demo_tv3);
                                            TextView login_zhongxin_demo_tv4 = (TextView) demo4.findViewById(R.id.login_zhongxin_demo_tv4);
                                            TextView login_zhongxin_demo_tv5 = (TextView) demo4.findViewById(R.id.login_zhongxin_demo_tv5);
                                            ImageView login_zhongxin_demo_iv1 = (ImageView) demo4.findViewById(R.id.login_zhongxin_demo_iv1);
                                            final CircleImageView login_zhongxin_demo_touxiang = (CircleImageView) demo4.findViewById(R.id.login_zhongxin_demo_touxiang);
                                            JSONObject obj1 = arr.getJSONObject(num_geren + 3);
                                            beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                                            biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                                            login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                                            login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                                            login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                                            int time = obj1.getInt("duration");
                                            login_zhongxin_demo_tv4.setText(time / 60 + " min");
                                            int col = time * 355 / 3600;
                                            login_zhongxin_demo_tv5.setText(col + " col");
                                            RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                                            ImageRequest imageRequest = new ImageRequest(
                                                    obj1.getString("wxPortrait"),
                                                    new Response.Listener<Bitmap>() {
                                                        @Override
                                                        public void onResponse(Bitmap response) {
                                                            login_zhongxin_demo_touxiang.setImageBitmap(response);
                                                            map.put(num_geren + "num4", response);
                                                        }
                                                    }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                                @Override
                                                public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                                }
                                            });
                                            mQueue.add(imageRequest);
                                        } else {
                                            demo4.setVisibility(View.GONE);
                                        }

                                    } else {
                                        View v1_geren = LayoutInflater.from(LoginActivity.this).inflate(R.layout.login_zhongxin_viewpager_demo, null);
                                        viewContainter_geren.add(v1_geren);
                                    }

                                }catch (JSONException e){
                                    e.printStackTrace();
                                }
                            }
                            login_zhongxin_yema.setText("1/"+viewContainter_geren.size());
                            mAdapter_geren.notifyDataSetChanged();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }

        );
        rq.add(request);

//        login_zhongxin_yema.setText("1/"+viewContainter_geren.size());
        mAdapter_geren = new DownAdapter_Geren();
        viewpager_geren.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    login_zhongxin_left.setImageResource(R.drawable.login_zhongxin_left1);
                    login_zhongxin_right.setImageResource(R.drawable.login_zhongxin_right1);
                }else{
                    login_zhongxin_left.setImageResource(R.drawable.login_zhongxin_left);
                    login_zhongxin_right.setImageResource(R.drawable.login_zhongxin_right);
                }
            }
        });
        viewpager_geren.setAdapter(mAdapter_geren);
        viewpager_geren.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                login_zhongxin_yema.setText(position + 1 + "/" + viewContainter_geren.size());
                if (position == 0) {
                    login_zhongxin_left.setVisibility(View.GONE);
                    if (viewContainter_geren.size() > 1) {
                        login_zhongxin_right.setVisibility(View.VISIBLE);
                    } else {
                        login_zhongxin_right.setVisibility(View.GONE);
                    }

                }
                if (position > 0 && viewContainter_geren.size() - 1 > position) {
                    login_zhongxin_right.setVisibility(View.VISIBLE);
                    login_zhongxin_left.setVisibility(View.VISIBLE);

                }
                if (position == viewContainter_geren.size() - 1) {
                    login_zhongxin_left.setVisibility(View.VISIBLE);
                    login_zhongxin_right.setVisibility(View.GONE);
                }
                if(position!=0&&shuzu_geren[position]==false){
                    num_geren=position*4;
                    try {
                        View v1_geren =viewContainter_geren.get(position);
                        LoginZhongxinDemo demo1=(LoginZhongxinDemo)v1_geren.findViewById(R.id.login_zhongxin_demo1);
                        LoginZhongxinDemo demo2=(LoginZhongxinDemo)v1_geren.findViewById(R.id.login_zhongxin_demo2);
                        LoginZhongxinDemo demo3=(LoginZhongxinDemo)v1_geren.findViewById(R.id.login_zhongxin_demo3);
                        LoginZhongxinDemo demo4=(LoginZhongxinDemo)v1_geren.findViewById(R.id.login_zhongxin_demo4);
                        if(num_geren<arr_geren.length()){
                            ImageView login_zhongxin_demo_bg=(ImageView)demo1.findViewById(R.id.login_zhongxin_demo_bg);
                            TextView login_zhongxin_demo_tv1=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv1);
                            TextView login_zhongxin_demo_tv2=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv2);
                            TextView login_zhongxin_demo_tv3=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv3);
                            TextView login_zhongxin_demo_tv4=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv4);
                            TextView login_zhongxin_demo_tv5=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv5);
                            ImageView login_zhongxin_demo_iv1=(ImageView)demo1.findViewById(R.id.login_zhongxin_demo_iv1);
                            final CircleImageView login_zhongxin_demo_touxiang=(CircleImageView)demo1.findViewById(R.id.login_zhongxin_demo_touxiang);
                            JSONObject obj1=arr_geren.getJSONObject(num_geren);
                            beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                            biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                            login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                            login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                            login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                            int time=obj1.getInt("duration");
                            login_zhongxin_demo_tv4.setText(time/60+" min");
                            int col=time*355/3600;
                            login_zhongxin_demo_tv5.setText(col+" col");
                            RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                            ImageRequest imageRequest = new ImageRequest(
                                    obj1.getString("wxPortrait"),
                                    new Response.Listener<Bitmap>() {
                                        @Override
                                        public void onResponse(Bitmap response) {
                                            login_zhongxin_demo_touxiang.setImageBitmap(response);
                                            map.put( num_geren+ "num1", response);
                                        }
                                    }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                }
                            });
                            mQueue.add(imageRequest);
                        }else{
                            demo1.setVisibility(View.GONE);
                        }
                        if(num_geren+1<arr_geren.length()){
                            ImageView login_zhongxin_demo_bg=(ImageView)demo2.findViewById(R.id.login_zhongxin_demo_bg);
                            TextView login_zhongxin_demo_tv1=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv1);
                            TextView login_zhongxin_demo_tv2=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv2);
                            TextView login_zhongxin_demo_tv3=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv3);
                            TextView login_zhongxin_demo_tv4=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv4);
                            TextView login_zhongxin_demo_tv5=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv5);
                            ImageView login_zhongxin_demo_iv1=(ImageView)demo2.findViewById(R.id.login_zhongxin_demo_iv1);
                            final CircleImageView login_zhongxin_demo_touxiang=(CircleImageView)demo2.findViewById(R.id.login_zhongxin_demo_touxiang);
                            JSONObject obj1=arr_geren.getJSONObject(num_geren+1);
                            beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                            biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                            login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                            login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                            login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                            int time=obj1.getInt("duration");
                            login_zhongxin_demo_tv4.setText(time/60+" min");
                            int col=time*355/3600;
                            login_zhongxin_demo_tv5.setText(col+" col");
                            RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                            ImageRequest imageRequest = new ImageRequest(
                                    obj1.getString("wxPortrait"),
                                    new Response.Listener<Bitmap>() {
                                        @Override
                                        public void onResponse(Bitmap response) {
                                            login_zhongxin_demo_touxiang.setImageBitmap(response);
                                            map.put( num_geren+ "num2", response);
                                        }
                                    }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                }
                            });
                            mQueue.add(imageRequest);
                        }else{
                            demo2.setVisibility(View.GONE);
                        }
                        if(num_geren+2<arr_geren.length()){
                            ImageView login_zhongxin_demo_bg=(ImageView)demo3.findViewById(R.id.login_zhongxin_demo_bg);
                            TextView login_zhongxin_demo_tv1=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv1);
                            TextView login_zhongxin_demo_tv2=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv2);
                            TextView login_zhongxin_demo_tv3=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv3);
                            TextView login_zhongxin_demo_tv4=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv4);
                            TextView login_zhongxin_demo_tv5=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv5);
                            ImageView login_zhongxin_demo_iv1=(ImageView)demo3.findViewById(R.id.login_zhongxin_demo_iv1);
                            final CircleImageView login_zhongxin_demo_touxiang=(CircleImageView)demo3.findViewById(R.id.login_zhongxin_demo_touxiang);
                            JSONObject obj1=arr_geren.getJSONObject(num_geren+2);
                            beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                            biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                            login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                            login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                            login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                            int time=obj1.getInt("duration");
                            login_zhongxin_demo_tv4.setText(time/60+" min");
                            int col=time*355/3600;
                            login_zhongxin_demo_tv5.setText(col+" col");
                            RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                            ImageRequest imageRequest = new ImageRequest(
                                    obj1.getString("wxPortrait"),
                                    new Response.Listener<Bitmap>() {
                                        @Override
                                        public void onResponse(Bitmap response) {
                                            login_zhongxin_demo_touxiang.setImageBitmap(response);
                                            map.put( num_geren+ "num3", response);
                                        }
                                    }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                }
                            });
                            mQueue.add(imageRequest);
                        }else{
                            demo3.setVisibility(View.GONE);
                        }
                        if(num_geren+3<arr_geren.length()){
                            ImageView login_zhongxin_demo_bg=(ImageView)demo4.findViewById(R.id.login_zhongxin_demo_bg);
                            TextView login_zhongxin_demo_tv1=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv1);
                            TextView login_zhongxin_demo_tv2=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv2);
                            TextView login_zhongxin_demo_tv3=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv3);
                            TextView login_zhongxin_demo_tv4=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv4);
                            TextView login_zhongxin_demo_tv5=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv5);
                            ImageView login_zhongxin_demo_iv1=(ImageView)demo4.findViewById(R.id.login_zhongxin_demo_iv1);
                            final CircleImageView login_zhongxin_demo_touxiang=(CircleImageView)demo4.findViewById(R.id.login_zhongxin_demo_touxiang);
                            JSONObject obj1=arr_geren.getJSONObject(num_geren+3);
                            beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                            biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                            login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                            login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                            login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                            int time=obj1.getInt("duration");
                            login_zhongxin_demo_tv4.setText(time/60+" min");
                            int col=time*355/3600;
                            login_zhongxin_demo_tv5.setText(col+" col");
                            RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                            ImageRequest imageRequest = new ImageRequest(
                                    obj1.getString("wxPortrait"),
                                    new Response.Listener<Bitmap>() {
                                        @Override
                                        public void onResponse(Bitmap response) {
                                            login_zhongxin_demo_touxiang.setImageBitmap(response);
                                            map.put( num_geren+ "num4", response);
                                        }
                                    }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                }
                            });
                            mQueue.add(imageRequest);
                        }else{
                            demo4.setVisibility(View.GONE);
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        RequestQueue rq1 = Volley.newRequestQueue(this.getApplicationContext());
        JsonObjectRequest request1 = new JsonObjectRequest("http://61.191.46.214:8087/checkin/shared/all?region=23", null,
                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject jsonObject) {
                        try {
                            JSONObject obj=jsonObject.getJSONObject("data");
                            JSONArray arr=obj.getJSONArray("list");
                            arr_all=arr;
                            int a=arr.length()/4;
                            if(arr.length()%4!=0){
                                a+=1;
                            }
                            if(a==1){
                                login_zhongxin_right.setVisibility(View.GONE);
                            }
                            for (int i=0;i<a;i++){
                                try{
                                if(i==0){
                                    View v1_geren = LayoutInflater.from(LoginActivity.this).inflate(R.layout.login_zhongxin_viewpager_demo, null);
                                    viewContainter_all.add(v1_geren);
                                    LoginZhongxinDemo demo1=(LoginZhongxinDemo)v1_geren.findViewById(R.id.login_zhongxin_demo1);
                                    LoginZhongxinDemo demo2=(LoginZhongxinDemo)v1_geren.findViewById(R.id.login_zhongxin_demo2);
                                    LoginZhongxinDemo demo3=(LoginZhongxinDemo)v1_geren.findViewById(R.id.login_zhongxin_demo3);
                                    LoginZhongxinDemo demo4=(LoginZhongxinDemo)v1_geren.findViewById(R.id.login_zhongxin_demo4);
                                    if(num_all<arr.length()){
                                        ImageView login_zhongxin_demo_bg=(ImageView)demo1.findViewById(R.id.login_zhongxin_demo_bg);
                                        TextView login_zhongxin_demo_tv1=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv1);
                                        TextView login_zhongxin_demo_tv2=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv2);
                                        TextView login_zhongxin_demo_tv3=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv3);
                                        TextView login_zhongxin_demo_tv4=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv4);
                                        TextView login_zhongxin_demo_tv5=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv5);
                                        ImageView login_zhongxin_demo_iv1=(ImageView)demo1.findViewById(R.id.login_zhongxin_demo_iv1);
                                        final CircleImageView login_zhongxin_demo_touxiang=(CircleImageView)demo1.findViewById(R.id.login_zhongxin_demo_touxiang);
                                        JSONObject obj1=arr.getJSONObject(num_all);
                                        beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                                        biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                                        login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                                        login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                                        login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                                        int time=obj1.getInt("duration");
                                        login_zhongxin_demo_tv4.setText(time/60+" min");
                                        int col=time*355/3600;
                                        login_zhongxin_demo_tv5.setText(col+" col");
                                        RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                                        ImageRequest imageRequest = new ImageRequest(
                                                obj1.getString("wxPortrait"),
                                                new Response.Listener<Bitmap>() {
                                                    @Override
                                                    public void onResponse(Bitmap response) {
                                                        login_zhongxin_demo_touxiang.setImageBitmap(response);
                                                        map.put( num_all+ "anum1", response);
                                                    }
                                                }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                            @Override
                                            public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                            }
                                        });
                                        mQueue.add(imageRequest);
                                    }else{
                                        demo1.setVisibility(View.GONE);
                                    }
                                    if(num_all+1<arr.length()){
                                        ImageView login_zhongxin_demo_bg=(ImageView)demo2.findViewById(R.id.login_zhongxin_demo_bg);
                                        TextView login_zhongxin_demo_tv1=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv1);
                                        TextView login_zhongxin_demo_tv2=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv2);
                                        TextView login_zhongxin_demo_tv3=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv3);
                                        TextView login_zhongxin_demo_tv4=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv4);
                                        TextView login_zhongxin_demo_tv5=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv5);
                                        ImageView login_zhongxin_demo_iv1=(ImageView)demo2.findViewById(R.id.login_zhongxin_demo_iv1);
                                        final CircleImageView login_zhongxin_demo_touxiang=(CircleImageView)demo2.findViewById(R.id.login_zhongxin_demo_touxiang);
                                        JSONObject obj1=arr.getJSONObject(num_all+1);
                                        beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                                        biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                                        login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                                        login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                                        login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                                        int time=obj1.getInt("duration");
                                        login_zhongxin_demo_tv4.setText(time/60+" min");
                                        int col=time*355/3600;
                                        login_zhongxin_demo_tv5.setText(col+" col");
                                        RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                                        ImageRequest imageRequest = new ImageRequest(
                                                obj1.getString("wxPortrait"),
                                                new Response.Listener<Bitmap>() {
                                                    @Override
                                                    public void onResponse(Bitmap response) {
                                                        login_zhongxin_demo_touxiang.setImageBitmap(response);
                                                        map.put( num_all+ "anum2", response);
                                                    }
                                                }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                            @Override
                                            public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                            }
                                        });
                                        mQueue.add(imageRequest);
                                    }else{
                                        demo2.setVisibility(View.GONE);
                                    }
                                    if(num_all+2<arr.length()){
                                        ImageView login_zhongxin_demo_bg=(ImageView)demo3.findViewById(R.id.login_zhongxin_demo_bg);
                                        TextView login_zhongxin_demo_tv1=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv1);
                                        TextView login_zhongxin_demo_tv2=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv2);
                                        TextView login_zhongxin_demo_tv3=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv3);
                                        TextView login_zhongxin_demo_tv4=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv4);
                                        TextView login_zhongxin_demo_tv5=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv5);
                                        ImageView login_zhongxin_demo_iv1=(ImageView)demo3.findViewById(R.id.login_zhongxin_demo_iv1);
                                        final CircleImageView login_zhongxin_demo_touxiang=(CircleImageView)demo3.findViewById(R.id.login_zhongxin_demo_touxiang);
                                        JSONObject obj1=arr.getJSONObject(num_all+2);
                                        beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                                        biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                                        login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                                        login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                                        login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                                        int time=obj1.getInt("duration");
                                        login_zhongxin_demo_tv4.setText(time/60+" min");
                                        int col=time*355/3600;
                                        login_zhongxin_demo_tv5.setText(col+" col");
                                        RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                                        ImageRequest imageRequest = new ImageRequest(
                                                obj1.getString("wxPortrait"),
                                                new Response.Listener<Bitmap>() {
                                                    @Override
                                                    public void onResponse(Bitmap response) {
                                                        login_zhongxin_demo_touxiang.setImageBitmap(response);
                                                        map.put( num_all+ "anum3", response);
                                                    }
                                                }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                            @Override
                                            public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                            }
                                        });
                                        mQueue.add(imageRequest);
                                    }else{
                                        demo3.setVisibility(View.GONE);
                                    }
                                    if(num_all+3<arr.length()){
                                        ImageView login_zhongxin_demo_bg=(ImageView)demo4.findViewById(R.id.login_zhongxin_demo_bg);
                                        TextView login_zhongxin_demo_tv1=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv1);
                                        TextView login_zhongxin_demo_tv2=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv2);
                                        TextView login_zhongxin_demo_tv3=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv3);
                                        TextView login_zhongxin_demo_tv4=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv4);
                                        TextView login_zhongxin_demo_tv5=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv5);
                                        ImageView login_zhongxin_demo_iv1=(ImageView)demo4.findViewById(R.id.login_zhongxin_demo_iv1);
                                        final CircleImageView login_zhongxin_demo_touxiang=(CircleImageView)demo4.findViewById(R.id.login_zhongxin_demo_touxiang);
                                        JSONObject obj1=arr.getJSONObject(num_all+3);
                                        beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                                        biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                                        login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                                        login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                                        login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                                        int time=obj1.getInt("duration");
                                        login_zhongxin_demo_tv4.setText(time/60+" min");
                                        int col=time*355/3600;
                                        login_zhongxin_demo_tv5.setText(col+" col");
                                        RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                                        ImageRequest imageRequest = new ImageRequest(
                                                obj1.getString("wxPortrait"),
                                                new Response.Listener<Bitmap>() {
                                                    @Override
                                                    public void onResponse(Bitmap response) {
                                                        login_zhongxin_demo_touxiang.setImageBitmap(response);
                                                        map.put( num_all+ "anum4", response);
                                                    }
                                                }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                            @Override
                                            public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                            }
                                        });
                                        mQueue.add(imageRequest);
                                    }else{
                                        demo4.setVisibility(View.GONE);
                                    }
                                }else{
                                    View v1_geren = LayoutInflater.from(LoginActivity.this).inflate(R.layout.login_zhongxin_viewpager_demo, null);
                                    viewContainter_all.add(v1_geren);
                                }

                            }catch (JSONException e){
                                    e.printStackTrace();
                                }
                            }
                            login_zhongxin_yema.setText("1/"+viewContainter_geren.size());
                            mAdapter_all.notifyDataSetChanged();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                volleyError.printStackTrace();
            }
        }

        );
        rq1.add(request1);
        mAdapter_all=new DownAdapter_All();
        viewpager_all.setAdapter(mAdapter_all);
        viewpager_all.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    login_zhongxin_left.setImageResource(R.drawable.login_zhongxin_left1);
                    login_zhongxin_right.setImageResource(R.drawable.login_zhongxin_right1);
                } else {
                    login_zhongxin_left.setImageResource(R.drawable.login_zhongxin_left);
                    login_zhongxin_right.setImageResource(R.drawable.login_zhongxin_right);
                }
            }
        });
        viewpager_all.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                login_zhongxin_yema.setText(position + 1 + "/" + viewContainter_all.size());
                if (position == 0) {
                    login_zhongxin_left.setVisibility(View.GONE);
                    if (viewContainter_all.size() > 1) {
                        login_zhongxin_right.setVisibility(View.VISIBLE);
                    } else {
                        login_zhongxin_right.setVisibility(View.GONE);
                    }
                }
                if (position > 0 && viewContainter_all.size() - 1 > position) {
                    login_zhongxin_right.setVisibility(View.VISIBLE);
                    login_zhongxin_left.setVisibility(View.VISIBLE);

                }
                if (position == viewContainter_all.size() - 1) {
                    login_zhongxin_left.setVisibility(View.VISIBLE);
                    login_zhongxin_right.setVisibility(View.GONE);
                }
                if(position!=0&&shuzu_all[position]==false){
                    num_all=position*4;
                    try {
                        View v1_geren =viewContainter_all.get(position);
                        LoginZhongxinDemo demo1=(LoginZhongxinDemo)v1_geren.findViewById(R.id.login_zhongxin_demo1);
                        LoginZhongxinDemo demo2=(LoginZhongxinDemo)v1_geren.findViewById(R.id.login_zhongxin_demo2);
                        LoginZhongxinDemo demo3=(LoginZhongxinDemo)v1_geren.findViewById(R.id.login_zhongxin_demo3);
                        LoginZhongxinDemo demo4=(LoginZhongxinDemo)v1_geren.findViewById(R.id.login_zhongxin_demo4);
                        if(num_all<arr_all.length()){
                            ImageView login_zhongxin_demo_bg=(ImageView)demo1.findViewById(R.id.login_zhongxin_demo_bg);
                            TextView login_zhongxin_demo_tv1=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv1);
                            TextView login_zhongxin_demo_tv2=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv2);
                            TextView login_zhongxin_demo_tv3=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv3);
                            TextView login_zhongxin_demo_tv4=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv4);
                            TextView login_zhongxin_demo_tv5=(TextView)demo1.findViewById(R.id.login_zhongxin_demo_tv5);
                            ImageView login_zhongxin_demo_iv1=(ImageView)demo1.findViewById(R.id.login_zhongxin_demo_iv1);
                            final CircleImageView login_zhongxin_demo_touxiang=(CircleImageView)demo1.findViewById(R.id.login_zhongxin_demo_touxiang);
                            JSONObject obj1=arr_all.getJSONObject(num_all);
                            beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                            biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                            login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                            login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                            login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                            int time=obj1.getInt("duration");
                            login_zhongxin_demo_tv4.setText(time/60+" min");
                            int col=time*355/3600;
                            login_zhongxin_demo_tv5.setText(col+" col");
                            RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                            ImageRequest imageRequest = new ImageRequest(
                                    obj1.getString("wxPortrait"),
                                    new Response.Listener<Bitmap>() {
                                        @Override
                                        public void onResponse(Bitmap response) {
                                            login_zhongxin_demo_touxiang.setImageBitmap(response);
                                            map.put( num_all+ "anum1", response);
                                        }
                                    }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                }
                            });
                            mQueue.add(imageRequest);
                        }else{
                            demo1.setVisibility(View.GONE);
                        }
                        if(num_all+1<arr_all.length()){
                            ImageView login_zhongxin_demo_bg=(ImageView)demo2.findViewById(R.id.login_zhongxin_demo_bg);
                            TextView login_zhongxin_demo_tv1=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv1);
                            TextView login_zhongxin_demo_tv2=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv2);
                            TextView login_zhongxin_demo_tv3=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv3);
                            TextView login_zhongxin_demo_tv4=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv4);
                            TextView login_zhongxin_demo_tv5=(TextView)demo2.findViewById(R.id.login_zhongxin_demo_tv5);
                            ImageView login_zhongxin_demo_iv1=(ImageView)demo2.findViewById(R.id.login_zhongxin_demo_iv1);
                            final CircleImageView login_zhongxin_demo_touxiang=(CircleImageView)demo2.findViewById(R.id.login_zhongxin_demo_touxiang);
                            JSONObject obj1=arr_all.getJSONObject(num_all+1);
                            beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                            biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                            login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                            login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                            login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                            int time=obj1.getInt("duration");
                            login_zhongxin_demo_tv4.setText(time/60+" min");
                            int col=time*355/3600;
                            login_zhongxin_demo_tv5.setText(col + " col");
                            RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                            ImageRequest imageRequest = new ImageRequest(
                                    obj1.getString("wxPortrait"),
                                    new Response.Listener<Bitmap>() {
                                        @Override
                                        public void onResponse(Bitmap response) {
                                            login_zhongxin_demo_touxiang.setImageBitmap(response);
                                            map.put( num_all+ "anum2", response);
                                        }
                                    }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                }
                            });
                            mQueue.add(imageRequest);
                        }else{
                            demo2.setVisibility(View.GONE);
                        }
                        if(num_all+2<arr_all.length()){
                            ImageView login_zhongxin_demo_bg=(ImageView)demo3.findViewById(R.id.login_zhongxin_demo_bg);
                            TextView login_zhongxin_demo_tv1=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv1);
                            TextView login_zhongxin_demo_tv2=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv2);
                            TextView login_zhongxin_demo_tv3=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv3);
                            TextView login_zhongxin_demo_tv4=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv4);
                            TextView login_zhongxin_demo_tv5=(TextView)demo3.findViewById(R.id.login_zhongxin_demo_tv5);
                            ImageView login_zhongxin_demo_iv1=(ImageView)demo3.findViewById(R.id.login_zhongxin_demo_iv1);
                            final CircleImageView login_zhongxin_demo_touxiang=(CircleImageView)demo3.findViewById(R.id.login_zhongxin_demo_touxiang);
                            JSONObject obj1=arr_all.getJSONObject(num_all+2);
                            beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                            biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                            login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                            login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                            login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                            int time=obj1.getInt("duration");
                            login_zhongxin_demo_tv4.setText(time/60+" min");
                            int col=time*355/3600;
                            login_zhongxin_demo_tv5.setText(col+" col");
                            RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                            ImageRequest imageRequest = new ImageRequest(
                                    obj1.getString("wxPortrait"),
                                    new Response.Listener<Bitmap>() {
                                        @Override
                                        public void onResponse(Bitmap response) {
                                            login_zhongxin_demo_touxiang.setImageBitmap(response);
                                            map.put( num_all+ "anum3", response);
                                        }
                                    }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                }
                            });
                            mQueue.add(imageRequest);
                        }else{
                            demo3.setVisibility(View.GONE);
                        }
                        if(num_all+3<arr_all.length()){
                            ImageView login_zhongxin_demo_bg=(ImageView)demo4.findViewById(R.id.login_zhongxin_demo_bg);
                            TextView login_zhongxin_demo_tv1=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv1);
                            TextView login_zhongxin_demo_tv2=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv2);
                            TextView login_zhongxin_demo_tv3=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv3);
                            TextView login_zhongxin_demo_tv4=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv4);
                            TextView login_zhongxin_demo_tv5=(TextView)demo4.findViewById(R.id.login_zhongxin_demo_tv5);
                            ImageView login_zhongxin_demo_iv1=(ImageView)demo4.findViewById(R.id.login_zhongxin_demo_iv1);
                            final CircleImageView login_zhongxin_demo_touxiang=(CircleImageView)demo4.findViewById(R.id.login_zhongxin_demo_touxiang);
                            JSONObject obj1=arr_all.getJSONObject(num_all+3);
                            beijing_huan(obj1.getString("category"), login_zhongxin_demo_bg);
                            biaoqing_huan(obj1.getInt("emoji"), login_zhongxin_demo_iv1);
                            login_zhongxin_demo_tv1.setText(obj1.getString("wxNickname"));
                            login_zhongxin_demo_tv2.setText(obj1.getString("datetime"));
                            login_zhongxin_demo_tv3.setText(obj1.getString("title"));
                            int time=obj1.getInt("duration");
                            login_zhongxin_demo_tv4.setText(time/60+" min");
                            int col=time*355/3600;
                            login_zhongxin_demo_tv5.setText(col+" col");
                            RequestQueue mQueue = Volley.newRequestQueue(LoginActivity.this);
                            ImageRequest imageRequest = new ImageRequest(
                                    obj1.getString("wxPortrait"),
                                    new Response.Listener<Bitmap>() {
                                        @Override
                                        public void onResponse(Bitmap response) {
                                            login_zhongxin_demo_touxiang.setImageBitmap(response);
                                            map.put( num_all+ "num4", response);
                                        }
                                    }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
//                                    erweima_login.setImageResource(R.drawable.default_image);
                                }
                            });
                            mQueue.add(imageRequest);
                        }else{
                            demo4.setVisibility(View.GONE);
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        initProductInfo(new ProductInitCallback() {
            @Override
            public void afterProductInited() {
                int region = ProductInfo.getInstance().region;
                RequestQueue rq = Volley.newRequestQueue(LoginActivity.this.getApplicationContext());

                String url = new ApiBuilder(ConfigUtils.Channel.CID_CURRENT)
                        .atPort(ConfigUtils.Port.CHECKIN)
                        .withApi(ConfigUtils.Api.CHECKIN_GET_TOTAL)
                        .addParam("deviceid", device_id)
                        .addParam("region", region)
                        .create();
                JsonObjectRequest request = new JsonObjectRequest(
                        url, null,
                        new Response.Listener<JSONObject>() {

                            @Override
                            public void onResponse(JSONObject jsonObject) {
                                try {
                                    JSONObject obj = jsonObject.getJSONObject("result");
//										rank.setText(device_id);

                                    int num_time = obj.getInt("durationTotal");
                                    int m = num_time / 60 % 60;
                                    int h = m / 60;
//                                    View v1 = viewContainer.get(0);
//                                    TextView allTime = (TextView) v1.findViewById(R.id.all_time);
//                                    TextView allCalorie = (TextView) v1.findViewById(R.id.all_calorie);
//                                    allTime.setText(h + "小时" + m + "分钟");
//
//                                    int kaluli = num_time / 10;
//                                    allCalorie.setText(kaluli + "大卡");

                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                    }
                }

                );
                rq.add(request);
            }
        });
        RequestQueue rq_jilu = Volley.newRequestQueue(LoginActivity.this.getApplicationContext());

        String url = new ApiBuilder(ConfigUtils.Channel.CID_CURRENT)
                .atPort(ConfigUtils.Port.CHECKIN)
                .withApi(ConfigUtils.Api.CHECKIN_GET_TOTAL)
                .addParam("deviceid", Util.getDeviceId(LoginActivity.this))
                .addParam("region",23)
                .create();
        JsonObjectRequest request_jilu = new JsonObjectRequest(
                url, null,
                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject jsonObject) {
                        try {
                            JSONObject obj = jsonObject.getJSONObject("result");
//										rank.setText(device_id);

                            int num_time = obj.getInt("durationTotal");
                            int m = num_time / 60 % 60;
                            int h = m / 60;
                            View v1=viewContainter.get(0);
                            TextView allTime_h = (TextView)v1.findViewById(R.id.page1_iv1);
                            TextView allTime_m = (TextView)v1.findViewById(R.id.page1_iv2);
                            TextView allCalorie = (TextView)v1.findViewById(R.id.page1_iv3);
                            allTime_h.setText(h+"");
                            allTime_m.setText(m+"");
                            int kaluli=num_time*355/3600;
                            allCalorie.setText(kaluli+"");
                            View v2=viewContainter.get(1);
                            TextView allTime_h1 = (TextView)v2.findViewById(R.id.login_zhongxin_tv1);
                            TextView allTime_m1 = (TextView)v2.findViewById(R.id.login_zhongxin_tv2);
                            TextView allCalorie1 = (TextView)v2.findViewById(R.id.login_zhongxin_tv3);
                            TextView now_paiming = (TextView)v2.findViewById(R.id.login_zhongxin_tv4);
                            TextView pass = (TextView)v2.findViewById(R.id.login_zhongxin_tv5);
                            allTime_h1.setText(h+"");
                            allTime_m1.setText(m+"");
                            allCalorie1.setText(kaluli+"");
                            now_paiming.setText(obj.getInt("rank")+"");
                            pass.setText(obj.getInt("surpassed")+"%");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }

        );
        rq_jilu.add(request_jilu);
        yulanceshi();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_login, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    private class DownAdapter extends PagerAdapter {
        @Override
        public int getCount() {
            return viewContainter.size();
        }

        //滑动切换的时候销毁当前的组件
        @Override
        public void destroyItem(ViewGroup container, int position,
                                Object object) {
            ((ViewPager) container).removeView(viewContainter.get(position));
        }

        //每次滑动的时候生成的组件
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ((ViewPager) container).addView(viewContainter.get(position));
            return viewContainter.get(position);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public int getItemPosition(Object object) {
            return super.getItemPosition(object);
        }


    }
    private class DownAdapter_Geren extends PagerAdapter {
        @Override
        public int getCount() {
            return viewContainter_geren.size();
        }

        //滑动切换的时候销毁当前的组件
        @Override
        public void destroyItem(ViewGroup container, int position,
                                Object object) {
            ((ViewPager) container).removeView(viewContainter_geren.get(position));
        }

        //每次滑动的时候生成的组件
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ((ViewPager) container).addView(viewContainter_geren.get(position));
            return viewContainter_geren.get(position);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public int getItemPosition(Object object) {
            return super.getItemPosition(object);
        }


    }
    private class DownAdapter_All extends PagerAdapter {
        @Override
        public int getCount() {
            return viewContainter_all.size();
        }

        //滑动切换的时候销毁当前的组件
        @Override
        public void destroyItem(ViewGroup container, int position,
                                Object object) {
            ((ViewPager) container).removeView(viewContainter_all.get(position));
        }

        //每次滑动的时候生成的组件
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ((ViewPager) container).addView(viewContainter_all.get(position));
            return viewContainter_all.get(position);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public int getItemPosition(Object object) {
            return super.getItemPosition(object);
        }


    }
    public class TimeThread extends Thread {
        @Override
        public void run () {
            do {
                try {
                    Thread.sleep(1000);
                    Message msg = new Message();
                    msg.what = msgKey1;
                    mHandler.sendMessage(msg);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } while(true);
        }
    }
    private void initProductInfo(final ProductInitCallback callback) {
        RequestQueue rq = Volley.newRequestQueue(this);
        String url = new ApiBuilder(ConfigUtils.Channel.CID_CURRENT)
                .withApi(ConfigUtils.Api.PRODUCT_INFO)
                .create();
        JsonObjectRequest request = new JsonObjectRequest(url, null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject jsonObject) {
                        ProductInfo.getInstance().init(jsonObject);

                        if (callback != null) {
                            callback.afterProductInited();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {

            }
        });
        rq.add(request);
    }
    private interface ProductInitCallback {
        void afterProductInited();
    }
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage (Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case msgKey1:
                    long sysTime = System.currentTimeMillis();
                    CharSequence sysTimeStr = DateFormat.format("hh:mm aa", sysTime);
                    fit_main_time.setText(sysTimeStr);
                    break;

                default:
                    break;
            }
        }
    };
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            // 2秒之内连续点击两次back就退出app


            if (System.currentTimeMillis() - exitTime > 2000) {
                System.out.println(Toast.LENGTH_LONG);
                Toast.makeText(this, "再按一次退出玩吧", Toast.LENGTH_LONG).show();
                exitTime = System.currentTimeMillis();
            } else {
                Behavior.onAppEnd(LoginActivity.this);
                finish();
            }

            return true;
        }
        else if(demo2_iv1.isFocused() && keyCode==KeyEvent.KEYCODE_DPAD_UP){
            login_tv11.requestFocus();
            return true;
        }
        else if(demo2_iv2.isFocused() && keyCode==KeyEvent.KEYCODE_DPAD_UP){
            login_tv11.requestFocus();
            return true;
        }
        else if(demo2_iv3.isFocused() && keyCode==KeyEvent.KEYCODE_DPAD_UP){
            login_tv11.requestFocus();
            return true;
        }
        else if(demo2_iv4.isFocused() && keyCode==KeyEvent.KEYCODE_DPAD_UP){
            login_tv11.requestFocus();
            return true;
        }

        else if(demo2_iv5.isFocused() && keyCode==KeyEvent.KEYCODE_DPAD_UP){
            login_tv11.requestFocus();
            return true;
        }
        else if(login_zhongxin_geren_iv1.isFocused() && keyCode==KeyEvent.KEYCODE_DPAD_UP){
            login_tv21.requestFocus();
            return true;
        }
        else if(login_zhongxin_all_iv1.isFocused() && keyCode==KeyEvent.KEYCODE_DPAD_UP){
            login_tv21.requestFocus();
            return true;
        }else if(Loginpage3.shuaxin_button.isFocused() && keyCode==KeyEvent.KEYCODE_DPAD_UP){
            login_tv31.requestFocus();
            return true;
        }
        else if(login_tv31.isFocused() && keyCode==KeyEvent.KEYCODE_DPAD_DOWN){
            Loginpage3.shuaxin_button.requestFocus();
            return true;
        }
        else if(login_zhongxin_all_iv1.isFocused() && keyCode==KeyEvent.KEYCODE_DPAD_DOWN && viewContainter_all.size()==1){

            return true;
        }
        else if(login_zhongxin_geren_iv1.isFocused() && keyCode==KeyEvent.KEYCODE_DPAD_DOWN && viewContainter_geren.size()==1){

            return true;
        }
        else {
            return super.onKeyDown(keyCode, event);
        }

    }
    private void beijing_huan(String cote,ImageView iv){
        if(cote.equals("101")){
            iv.setImageResource(R.drawable.login_zhongxin_demo_mikeling);
        }if(cote.equals("102")){
            iv.setImageResource(R.drawable.login_zhongxin_demo_ruijian);
        }if(cote.equals("103")){
            iv.setImageResource(R.drawable.login_zhongxin_demo_zhengduoyan);
        }if(cote.equals("106")){
            iv.setImageResource(R.drawable.login_zhongxin_demo_jianshencao);
        }
        if(cote.equals("105")){
            iv.setImageResource(R.drawable.login_zhongxin_demo_bengbengtiao);
        }if(cote.equals("104")){
            iv.setImageResource(R.drawable.login_zhongxin_demo_wangguangcheng);
        }if(cote.equals("108")){
            iv.setImageResource(R.drawable.login_zhongxin_demo_jiewu);
        }if(cote.equals("109")){
            iv.setImageResource(R.drawable.login_zhongxin_demo_dupiwu);
        }

    }
    private void biaoqing_huan(int cote,ImageView iv){
        if(cote==1){
            iv.setImageResource(R.drawable.fit_daka_face1);
        }if(cote==2){
            iv.setImageResource(R.drawable.fit_daka_face2);
        }
        if(cote==3){
            iv.setImageResource(R.drawable.fit_daka_face3);
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Loginpage3.onActivityDestory();
        Iterator iter = map.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next(); Object key = entry.getKey();
            Object val = entry.getValue();
            Bitmap a=(Bitmap)val;
            a.recycle();
        }
        System.gc();
        DataReport.AppRetreat(this,"2000");
    }

    @Override
    protected void onResume() {
        super.onResume();
        // 检查最新的apk版本并提示是否下载
        if (!getSharedPreferences("apk_update", 0).getBoolean("is_update",
                false)) {
            getSharedPreferences("apk_update", 0).edit()
                    .putBoolean("is_update", true).commit();
//			updateAPK(getResources().getString(R.string.apk_update_json_url),
//					AppUtil.converVersionNameToInt(AppUtil.getAppVersionName(this)));

        }
    }
    /**
     * 更新apk
     *
     * @param url
     */
    private void updateAPK(String url, final int currVersion) {
        receiver = new DownloadTaskReceiver();
        JsonObjectRequest mJsonObjectRequest = new JsonObjectRequest(url, null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject obj) {
                        try {
                            JSONObject response=obj.getJSONObject("data");
                            // 版本是否更新 0否 1是
                            String versionName = response.getString("versionName");
                            if (AppUtil.converVersionNameToInt(versionName) > currVersion) {
                                // 获取apk下载地址
                                final String apkUpdateUrl = response
                                        .getString("apk");
                                // 是否强制更新 0否 1是
                                int isForceUpdate = response
                                        .getInt("isForce");

                                AlertDialog.Builder b2 = new AlertDialog.Builder(
                                        LoginActivity.this)
                                        .setTitle("提示")
                                        .setMessage("升级到最新版本")
                                        .setPositiveButton(
                                                "确定",
                                                new AlertDialog.OnClickListener() {
                                                    public void onClick(
                                                            DialogInterface dialog,
                                                            int which) {
                                                        Toast.makeText(
                                                                LoginActivity.this,
                                                                "开始下载！",
                                                                Toast.LENGTH_LONG)
                                                                .show();
                                                        download("",
                                                                apkUpdateUrl,
                                                                "wanba",
                                                                "", 0);
                                                    }
                                                });

                                if (isForceUpdate == 0) {
                                    b2.setNegativeButton("取消",
                                            new AlertDialog.OnClickListener() {

                                                @Override
                                                public void onClick(
                                                        DialogInterface dialog,
                                                        int which) {
                                                    dialog.dismiss();
                                                }
                                            });
                                    b2.setCancelable(true);
                                } else {
                                    b2.setCancelable(false);
                                }
                                b2.create();
                                b2.show();
                            }

                        } catch (NumberFormatException e) {
                            e.printStackTrace();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(LoginActivity.this, "更新访问失败！",
                        Toast.LENGTH_LONG).show();
            }
        });

        // 将 请求放入 请求队列
        AppUtil.getInstance(this).getRequestQueue().add(mJsonObjectRequest);

    }

    /**
     * 下载app具体操作
     *
     * @param appId
     * @param downloadUrl
     * @param appName
     * @param appDesc
     * @param appSize
     */
    public void download(String appId, String downloadUrl, String appName,
                         String appDesc, long appSize) {
        // 初始化DownloadTask实例
        DownloadTask aDownloadTask = new DownloadTask(appId,
                Uri.parse(downloadUrl), appName, appDesc, appSize);
        // 实例化DownloadManager.Request
        DownloadManager.Request request = new DownloadManager.Request(
                aDownloadTask.getDownloadURI());
        // 系统下载路径
        request.setDestinationInExternalFilesDir(LoginActivity.this,
                Environment.DIRECTORY_DOWNLOADS, appName + ".apk");

        // request.setShowRunningNotification(true);
        // 向队列加载一个新的下载项
        DownloadManager downloadManager = ((DownloadManager) LoginActivity.this
                .getSystemService(Activity.DOWNLOAD_SERVICE));
        long downloadId = downloadManager.enqueue(request);
        // 保存downloadId
        aDownloadTask.setDownloadId(downloadId);
        // 保存DownloadTask对象
        // tasks.add(aDownloadTask);
        // 过滤器 当前下载任务完成
        IntentFilter filter = new IntentFilter(
                DownloadManager.ACTION_DOWNLOAD_COMPLETE);
        // 注册并监听过滤器
        LoginActivity.this.registerReceiver(receiver, filter);

    }
    private  String jiami(String orderInfo){
//        String msg = "使用3DES对数据进行加密";
//        byte[] secretArr = DES3Utils.encryptMode(msg.getBytes());
//        String jiami=Base64.encodeToString(secretArr,Base64.DEFAULT);
//        String res = null;
//        try {
//            res = new String(DES3Utils.decryptMode(Base64.decode(jiami, Base64.DEFAULT)), "utf-8");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        Log.e("jiami","3des result " + msg.equals(res) + " res " + res + ", encrypt " + jiami);

        String jiami= Crypto.TripleDES.encrypt(orderInfo,"26f545c0d092463185acdd3e2c73fdda");
//        String jiemi=Crypto.TripleDES.decrypt(jiami,"36161889369a412b923af17dafb0fe88");
        Log.e("jiami",jiami);
//        Log.e("jiemi",jiemi);
        return jiami;
    }

    private void dinggou(){

        String need_jiami= "itvAccount="+AppUtil.STB.UserID+"|"+"productId=zg_wanba";
        String orderInfo=jiami(need_jiami);

        try {
            orderInfo= URLEncoder.encode(orderInfo,"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String url="http://61.191.45.118:7002/itv-api"+"/has_order?providerId="+"shzg"+"&orderInfo="+orderInfo;
        RequestQueue rq = Volley.newRequestQueue(LoginActivity.this.getApplicationContext());
        StringRequest request=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.e("response:",response);
                try {
                    JSONObject obj = new JSONObject(response);
                    int num=obj.getInt("ordered");
                    if(num!=0){
                        is_dinggou=true;
                    }else {
                        is_dinggou=false;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        rq.add(request);


    }
    HashMap<String, String> params=null;
    String  extraKey=null;
    @Override
    protected void onStart() {
        super.onStart();
        if(yema_num==0){
            DataReport.PageRetreat(LoginActivity.this,"1100","100010");
        }
        if(yema_num==1){
            DataReport.PageRetreat(LoginActivity.this,"1100","100011");
        }
        if(yema_num==2){
            DataReport.PageRetreat(LoginActivity.this,"1100","100012");
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        params=null;
        extraKey=null;
        if(yema_num==0){
            DataReport.PageRetreat(LoginActivity.this,"2100","100010");
        }
        if(yema_num==1){
            DataReport.PageRetreat(LoginActivity.this,"2100","100011");
        }
        if(yema_num==2){
            DataReport.PageRetreat(LoginActivity.this,"2100","100012");
        }
    }

    public void yulanceshi(){
        extraKey=this.getIntent().getStringExtra("extraKey");
        if(extraKey!=null){
            Intent it=new Intent();
            params  = new HashMap<String, String>();
            params.put("play_url", extraKey);
            for (String str : params.keySet()) {
                it.putExtra(str, params.get(str));
            }
            it.setClass(this,SimplePlayerActivity.class);
            SimplePlayerActivity.IS_YULAN=true;
            startActivity(it);

        }
    }
}
